﻿(function(win){
    var curColumnItem=null;

    win.bind4onLine=__bind4OnLine;
    win.bind4Index=__bind4Index;
    win.bind4List=__bind4List;
    win.setFont=__setFont;

    function gid(a){
        return(document.getElementById(a));
    }

    function __bind4Index(){
        __bind4IndexSubColumn();
        __bind4LoginForm();
    }

    function __bind4IndexSubColumn(){
        var _t=gid("pSubColumn"),_to;
        var _aa=[];
        var i,j;

        for(i=0,j=_t.children.length;i<j;i++){
            _to=_t.children[i];
            if(_to.tagName.toLowerCase()==="a" && /item/g.test(_to.className)){
                _to.onmouseover=__overColumnItem;
                if(/current/g.test(_to.className)){
                    curColumnItem=_to;
                    gid(curColumnItem.getAttribute("cid")).className="";
                }
            }
        }
    }

    function __bind4LoginForm(){
        var _t;

        _t=gid("imgYZM");
        _t.src="../funs/yzm.aspx?"+Math.random();
        _t.style.display="inline-block";

        _t=gid("btnRegister");
        _t.onclick=function(){
            window.location.href="../user/preRegister.aspx";
        };

        _t=gid("form1");
        _t.action="../user/login.aspx";
        _t.method="post";
        _t.onsubmit=__checkForm4IndexLogin;
    }

    function __checkForm4IndexLogin(){
        var _t;

        _t=gid("xm");
        if(_t.value.length<1){
            alert("请输入登录用户名！");
            return(false);
        }
        _t=gid("sfzh");
        if(_t.value.length!=18){
            alert("请输入18位身份证号！");
            return(false);
        }
        _t=gid("mm");
        if(_t.value.length<1){
            alert("请输入登录密码！");
            return(false);
        }
        _t=gid("yzm");
        if(_t.value.length!=4){
            alert("请输入4位的验证码！");
            return(false);
        }
        return(true);
    }

    function __overColumnItem(){
        var _t=this;
        if(/current/g.test(_t.className)){
            return;
        }

        _t.className="item current";
        curColumnItem.className="item";
        gid(curColumnItem.getAttribute("cid")).className="hidden";
        curColumnItem=_t;
        gid(curColumnItem.getAttribute("cid")).className="";
    }

    function __bind4List(){
        __bind4PageJump();
    }

    function __bind4PageJump(){
        var _t;

        _t=gid("jp");
        if(_t!=null)
            _t.onkeydown=__2JumpPage;
    }
    function __2JumpPage(){
        if(event.keyCode==13){
            var _pc=gid("pPageListContainer").getElementsByTagName("span");
            var _cp;
            var i,j;
            var _f;

            _cp=gid("jp").value.replace(/[^0-9]/g,"");
            if(_cp.length<1){
                alert("请正确输入跳转页码！");
                return;
            }
            _cp=parseInt(_cp);

            _f=false;
            for(i=0,j=_pc.length;i<j;i++){
                if(_pc[i].className=="pc"){
                    _pc=_pc[i];
                    _f=true;
                    break;
                }
            }
            if(!_f){return;}
            _pc=_pc.innerText;
            _pc=parseInt(_pc.substr(_pc.indexOf("/")+1));

            if(_cp>_pc){
                alert("当前共"+_pc+"页！");
                return;
            }
            window.location.href="?a="+_cp;
        }
    }

    function __bind4OnLine(){
        gid("form1").onsubmit=__checkOnLineForm;
        gid("btn2Index").onclick=__2Index;
    }

    function __2Index(){
        window.location.href="index.aspx";
    }

    function __checkOnLineForm(){
        var t,i,f;

        f=false;
        for(i=0;i<3;i++){
            t=document.getElementById("t"+(i+1));
            if(t.checked){
                f=true;
                break;
            }
        }

        if(!f){
            alert("请选择题库类别！");
            return(false);
        }
        return(true);
    }

    function __setFont(fs){
        var _t;

        _t=gid("readContent");
        _t.style.fontSize=fs+"px";
    }
})(window);
